from page.base_page import BasePage
from selenium.webdriver.common.by import By

class LoginPage(BasePage):
    # 元素定位器
    USERNAME_INPUT = (By.ID, 'username')
    PASSWORD_INPUT = (By.ID, 'password')
    LOGIN_BUTTON = (By.ID, 'login-button')
    ERROR_MESSAGE = (By.CSS_SELECTOR, '.error-message')
    
    def input_username(self, username):
        self.send_keys(self.USERNAME_INPUT, username)
    
    def input_password(self, password):
        self.send_keys(self.PASSWORD_INPUT, password)
    
    def click_login_button(self):
        self.click(self.LOGIN_BUTTON)
    
    def get_error_message(self):
        return self.get_text(self.ERROR_MESSAGE)
    
    def login(self, username, password):
        self.input_username(username)
        self.input_password(password)
        self.click_login_button()  